package vn.cent.game.cardtype.client;

import vn.cent.game.cardtype.main.CardTypeGameExtension;
import vn.cent.game.cardtype.server.RoomRemoved;

import com.smartfoxserver.v2.api.CreateRoomSettings;
import com.smartfoxserver.v2.entities.Room;
import com.smartfoxserver.v2.entities.SFSRoomRemoveMode;
import com.smartfoxserver.v2.entities.User;
import com.smartfoxserver.v2.entities.data.ISFSObject;
import com.smartfoxserver.v2.exceptions.SFSCreateRoomException;
import com.smartfoxserver.v2.extensions.BaseClientRequestHandler;

public class MakeRoom extends BaseClientRequestHandler {

	@Override
	public void handleClientRequest(User sender, ISFSObject sentData) {
		
		trace("[ClientRequest] Make room!!!!");
		CardTypeGameExtension gameExtension = (CardTypeGameExtension) getParentExtension();
		
		// Declare our vars
		String rName = "FakeData";
		String rPassword = "FakePassword";
		int rMaxPlayer = 5;
		
		// Unpack data
		
		
		// Create room settings with request information
		CreateRoomSettings rSettings = new CreateRoomSettings();
		rSettings.setName(rName);
		//rSettings.setPassword(rPassword);
		rSettings.setMaxUsers(rMaxPlayer);
		
		// Our room settings to improve performances
		rSettings.setGame(true);
		rSettings.setDynamic(true);
		rSettings.setAutoRemoveMode(SFSRoomRemoveMode.WHEN_EMPTY);
		
		Room room = null;
		
		try {
			room = this.getApi().createRoom(gameExtension.getParentZone(), rSettings, sender);
		} catch (SFSCreateRoomException e) {
			trace("[Server_CardType] Join room exception!!!");
			e.printStackTrace();
		}
		room.setActive(true);
		room.setPassword(rPassword);
	}

}
